package com.navinfo.platform.sparksql.api;

import com.navinfo.platform.sparksql.support.ResultSetCallback;
import com.navinfo.platform.sparksql.support.ResultSetExtractor;
import com.navinfo.platform.sparksql.support.ResultSetRowMapper;
import com.navinfo.platform.sparksql.support.SparkSQLException;

import java.util.List;

/**
 * SparkSQL的相关操作，只开放查询接口
 */
public interface SparkSQLOperations {
    /**
     * 通过hql查询数据，使用ResultSetExtractor提取结果对象T
     * @param hql
     * @param rse
     * @param <T>
     * @return
     * @throws SparkSQLException
     */
    <T> T query(String hql, ResultSetExtractor<T> rse) throws SparkSQLException;
    <T> T query(String hql, Object[] args, ResultSetExtractor<T> rse) throws SparkSQLException;

    /**
     * 通过hql查询数据，使用ResultSetCallback自己处理RS
     * @param hql
     * @param rch
     * @throws SparkSQLException
     */
    void query(String hql, ResultSetCallback rch) throws SparkSQLException;
    void query(String hql, Object[] args, ResultSetCallback rch) throws SparkSQLException;

    /**
     * 通过hql查询数据，使用ResultSetRowMapper提取一行数据
     * @param hql
     * @param rowMapper
     * @param <T>
     * @return
     * @throws SparkSQLException
     */
    <T> T queryForObject(String hql, ResultSetRowMapper<T> rowMapper) throws SparkSQLException;
    <T> T queryForObject(String hql, Object[] args, ResultSetRowMapper<T> rowMapper) throws SparkSQLException;

    /**
     * 通过hql查询数据，返回List对象，List中的元素为ResultSetRowMapper映射的结果
     * @param hql
     * @param rowMapper
     * @param <T>
     * @return
     * @throws SparkSQLException
     */
    <T> List<T> queryForList(String hql, ResultSetRowMapper<T> rowMapper) throws SparkSQLException;
    <T> List<T> queryForList(String hql, Object[] args, ResultSetRowMapper<T> rowMapper) throws SparkSQLException;

}
